## Convert-PsSpecVerbCSV.ps1
## Convert the Verbs and Parameters.csv into something we can manage more easily.

## Expected usage:
## 2) .\Convert-VerbCSV.ps1 '.\Verbs and Parameters.csv' | Export-Csv ConvertedVerbs.csv
## 3) Run Generate-PsSpecVerbSql.ps1, and pipe into createverbs.sql
## 4) Execute createverbs.sql on AspenManagement DB

param($path = $(throw "Please specify the location to the Verbs and Parameters CSV."))

$currentEntries = Import-Csv $path -Header Name,Definition,Comments,Examples,Pair,Obsoletes,Output
$verbType = $null

foreach($entry in $currentEntries)
{
    if($entry.Definition -eq "Definition")
    {
        switch ($entry.Name)
        {
            {
                "Common","Communication","Data","Diagnostic",
                "Lifecycle","Security","Restricted"
            } { $verbType = (-split $entry.Name)[0] }
            default { throw "Unrecognized Verb type: $($entry.Name)" }
        }
        continue
    }
    
    if($entry.Name)
    {
        $entry | Add-Member NoteProperty VerbType $verbType
        $entry.PSObject.Properties | Foreach { $entry.($_.Name) = $entry.($_.Name).Trim()  }
        $entry
    }
}
